#include "deletefielddialog.h"
#include "ui_deletefielddialog.h"

DeleteFieldDialog::DeleteFieldDialog(QStringList fieldListIn,QWidget *parent) :
    QDialog(parent),fieldList(fieldListIn),
    ui(new Ui::DeleteFieldDialog)
{
    ui->setupUi(this);
    iniMainDialog();

    connect(this,&DeleteFieldDialog::sigDeleteField,
            AppEvent::getInstance(),&AppEvent::on_DeleteField);

    connect(btnOK,&QPushButton::clicked,
            this,&DeleteFieldDialog::on_btnOK_clicked);
    connect(btnCancel,&QPushButton::clicked,
            this,&DeleteFieldDialog::on_btnCancel_clicked);
}

DeleteFieldDialog::~DeleteFieldDialog()
{
    delete ui;
}

void DeleteFieldDialog::iniMainDialog()
{
    QFormLayout *formLayout=new QFormLayout();
    comboxFieldList=new QComboBox();
    comboxFieldList->addItems(fieldList);
    formLayout->insertRow(0,QObject::tr("Field Name:"),comboxFieldList);
    btnOK=new QPushButton();
    btnOK->setText(QObject::tr("OK"));
    btnCancel=new QPushButton();
    btnCancel->setText(QObject::tr("Cancel"));
    QHBoxLayout *btnLayout=new QHBoxLayout();
    btnLayout->addWidget(btnOK);
    btnLayout->addWidget(btnCancel);
    QVBoxLayout *mainLayout=new QVBoxLayout();
    mainLayout->addLayout(formLayout);
    mainLayout->addLayout(btnLayout);
    this->setLayout(mainLayout);
}

void DeleteFieldDialog::on_btnOK_clicked()
{
    //QString field=comboxFieldList->currentText();
    int fieldIndex=comboxFieldList->currentIndex();
    emit sigDeleteField(fieldIndex);
    this->close();

}

void DeleteFieldDialog::on_btnCancel_clicked()
{
    this->close();
}
